import React from "react";
import BaseChart from "../Base";
import { ChartProps } from "../interface";
import transform from "./transform";

export interface LineChartConfig {
  /**
   * X轴字段
   */
  xField: string;
  /**
   * Y轴字段，可能有多个
   */
  yFields: string[];
  xAxisLabelFormatter?: string | Function;
  yAxisLabelFormatter?: string | Function;
  tooltipFormatter?: string | Function;
  brushable?: boolean;
}

export interface LineChartProps extends ChartProps {
  config: LineChartConfig;
  data: any[];
}

const LineChart: React.FC<LineChartProps> = ({ ...props }) => {
  const { data, config } = props;
  const option = transform(data, config);

  return <BaseChart {...props} option={option} />;
};

LineChart.displayName = "LineChart";

export default LineChart;
